package springMvc;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class DownUpLoadFileController {
	@RequestMapping("DownLoad")
	public void DownUploadFie(@RequestParam("fName") String fileName, HttpServletRequest request,HttpServletResponse response) {
		String path = request.getServletContext().getRealPath("/phone");
		try {
			response.setHeader("Content-Disposition", "attachment;filename="+new String(fileName.getBytes("UTF-8"),"ISO-8859-1"));
			FileInputStream fis=new FileInputStream(new File(path,fileName));
			OutputStream os=response.getOutputStream();
			byte[] b=new byte[1024];
		int	lenth=fis.read(b);
		while(lenth!=-1){
			os.write(b, 0, lenth);
			lenth=fis.read(b);
		}
		os.close();
		fis.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
}
